package com.liang.bishi.jd;

import java.util.*;

/**
 * 9.14京东笔试第一题
 * 题目：分割序列，代价为分割后左右两个子序列元素和的乘，求序列分割的最小代价
 * 输入：
 * 5
 * 1 2 3 4 5
 * 输出：
 * 14
 * 解释：1 * (2+3+4+5) = 14
 */
public class Problem1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 读取输入
        int n = Integer.parseInt(in.nextLine());
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = in.nextInt();
        }
        System.out.println(getMinCost(nums, n));
    }

    public static long getMinCost(int[] nums, int n) {
        int[] preSum = new int[n + 1];
        // 初始化前缀和 [0, 1, 3, 6, 10, 15]
        for (int i = 0; i < n; i++) {
            preSum[i + 1] = preSum[i] + nums[i];
        }
        // 要取 Long 的 Max
        long minCost = Long.MAX_VALUE;
        // 从第一个数字开始分割计算
        for (int i = 1; i < n; i++) {
            int left = preSum[i];
            int right = preSum[n] - preSum[i];
            minCost = Math.min(minCost, (long) left * right);
        }
        return minCost;
    }

    public void get() {
        Scanner in = new Scanner(System.in);
        int n = Integer.parseInt(in.nextLine());
        int[] preSum = new int[n + 1];
        String[] as = in.nextLine().split(" ");
        for (int i = 0; i < n; i++) {
            preSum[i + 1] = preSum[i] + Integer.parseInt(as[i]);
        }
        long ans = Long.MAX_VALUE;
        for (int i = 1; i <= n - 1; ++i) {
            int left = preSum[i];
            int right = preSum[n] - preSum[i];
            ans = Math.min(ans, (long) left * right);
        }
        System.out.println(ans);
    }
}
